<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/12/21
 * Time: 16:32
 */
declare(strict_types=1);
namespace app\api\controller;
use app\api\validate\User;
use app\BaseController;

class Login extends BaseController{
    public function index() :object {
        if(!$this->request->isPost()){
            return  show(config('status.error'),'非法请求');;
        }
        $poneNumber = $this->request->param("phone_number",'','trim');
        $code = input("code",0,"intval");
        $type = input("type",0,"intval");
        //参数校验
        $data = [
            "phone_number" =>$poneNumber,
            "code" =>$code,
            "type" =>$type,
        ];
        $validate= new User();
        if(!$validate->scene("login")->check($data)){
            return  show(config('status.error'),$validate->getError());
        }
        //business层处理数据
        try{
            $result = (new \app\common\business\User())->Login($data);
        }catch (\Exception $e){
            return  show(config('status.error'),$e->getMessage());;
        }
        if($result){
            return  show(config('status.success'),'登录成功',$result);;
        }
        return  show(config('status.error'),'登录失败');;
    }
}